package com.nkl.admin.manager;

import com.nkl.common.dao.BaseDao;
import com.nkl.common.util.Md5;
import com.nkl.common.util.StringUtil;
import com.nkl.common.util.Transcode;
import com.nkl.page.dao.*;
import com.nkl.page.domain.*;

import java.sql.Connection;
import java.util.List;

public class AdminManager {

	InfosDao infosDao = new InfosDao();
	NoteDao noteDao = new NoteDao();
	CommentDao commentDao = new CommentDao();
	CommentReplyDao commentReplyDao = new CommentReplyDao();
	UserDao userDao = new UserDao();
	UserNoDao userNoDao = new UserNoDao();
	
	
	/**
	 * @Title: listUserNos
	 * @Description: 查询学号
	 * @param userNo
	 * @param sum
	 * @return List<UserNo>
	 */
	public List<UserNo>  listUserNos(UserNo userNo,int[] sum){
		Connection conn = BaseDao.getConnection();
		if (sum!=null) {
			sum[0] = userNoDao.listUserNosCount(userNo, conn);
		}
		List<UserNo> userNos = userNoDao.listUserNos(userNo,conn);
		
		BaseDao.closeDB(null, null, conn);
		return userNos;
	}
	
	/**
	 * @Title: addUserNo
	 * @Description: 添加学号
	 * @param userNo
	 * @return void
	 */
	public void  addUserNo(UserNo userNo){
		Connection conn = BaseDao.getConnection();
		userNoDao.addUserNo(userNo, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: delUserNos
	 * @Description: 删除学号信息
	 * @param userNo
	 * @return void
	 */
	public void  delUserNos(UserNo userNo){
		Connection conn = BaseDao.getConnection();
		userNoDao.delUserNos(userNo.getIds().split(","), conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: listUsers
	 * @Description: 用户查询
	 * @param user
	 * @return List<User>
	 */
	public List<User>  listUsers(User user,int[] sum){
		Connection conn = BaseDao.getConnection();
		if (sum!=null) {
			sum[0] = userDao.listUsersCount(user, conn);
		}
		List<User> users = userDao.listUsers(user,conn);
		
		BaseDao.closeDB(null, null, conn);
		return users;
	}
	
	/**
	 * @Title: editUser
	 * @Description: 编辑用户信息
	 * @param user
	 * @return void
	 */
	public void  editUser(User user){
		Connection conn = BaseDao.getConnection();
		
		userDao.updateUser(user,conn);
		
		BaseDao.closeDB(null, null, conn);
	}

	/**
	 * @Title: getUser
	 * @Description: 用户查询
	 * @param user
	 * @return User
	 */
	public User  getUser(User user){
		Connection conn = BaseDao.getConnection();
		User _user = userDao.getUser(user, conn);
		BaseDao.closeDB(null, null, conn);
		return _user;
	}
	 
	/**
	 * @Title: addUser
	 * @Description: 添加用户
	 * @param user
	 * @return void
	 */
	public void  addUser(User user){
		Connection conn = BaseDao.getConnection();
		userDao.addUser(user, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: updateUser
	 * @Description: 更新用户信息
	 * @param user
	 * @return void
	 */
	public void  updateUser(User user){
		Connection conn = BaseDao.getConnection();
		if (!StringUtil.isEmptyString(user.getUser_pass())) {
			user.setUser_pass(Md5.makeMd5(user.getUser_pass()));
		}
		userDao.updateUser(user, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: delUsers
	 * @Description: 删除用户信息
	 * @param user
	 * @return void
	 */
	public void  delUsers(User user){
		Connection conn = BaseDao.getConnection();
		userDao.delUsers(user.getIds().split(","), conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: listNotes
	 * @Description: 公告查询
	 * @param note
	 * @return List<Note>
	 */
	public List<Note>  listNotes(Note note,int[] sum){
		Connection conn = BaseDao.getConnection();
		if (sum!=null) {
			sum[0] = noteDao.listNotesCount(note, conn);
		}
		List<Note> notes = noteDao.listNotes(note,conn);
		
		BaseDao.closeDB(null, null, conn);
		return notes;
	}
	
	/**
	 * @Title: editNote
	 * @Description: 编辑公告信息
	 * @param note
	 * @return void
	 */
	public void  editNote(Note note){
		Connection conn = BaseDao.getConnection();
		//公告内容编码后保存
		note.setNote_content(Transcode.htmlEncode(note.getNote_content()));
		noteDao.updateNote(note,conn);
		
		BaseDao.closeDB(null, null, conn);
	}

	/**
	 * @Title: getNote
	 * @Description: 公告查询
	 * @param note
	 * @return Note
	 */
	public Note  getNote(Note note){
		Connection conn = BaseDao.getConnection();
		Note _note = noteDao.getNote(note, conn);
		BaseDao.closeDB(null, null, conn);
		return _note;
	}
	 
	/**
	 * @Title: addNote
	 * @Description: 添加公告
	 * @param note
	 * @return void
	 */
	public void  addNote(Note note){
		Connection conn = BaseDao.getConnection();
		//公告内容编码后保存
		note.setNote_content(Transcode.htmlEncode(note.getNote_content()));
		noteDao.addNote(note, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: updateNote
	 * @Description: 更新公告信息
	 * @param note
	 * @return void
	 */
	public void  updateNote(Note note){
		Connection conn = BaseDao.getConnection();
		//公告内容编码后保存
		note.setNote_content(Transcode.htmlEncode(note.getNote_content()));
		noteDao.updateNote(note, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: delNotes
	 * @Description: 删除公告信息
	 * @param note
	 * @return void
	 */
	public void  delNotes(Note note){
		Connection conn = BaseDao.getConnection();
		noteDao.delNotes(note.getIds().split(","), conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: listInfoss
	 * @Description: 资讯查询
	 * @param infos
	 * @return List<Infos>
	 */
	public List<Infos>  listInfoss(Infos infos,int[] sum){
		Connection conn = BaseDao.getConnection();
		if (sum!=null) {
			sum[0] = infosDao.listInfossCount(infos, conn);
		}
		List<Infos> infoss = infosDao.listInfoss(infos,conn);
		
		BaseDao.closeDB(null, null, conn);
		return infoss;
	}
	
	/**
	 * @Title: editInfos
	 * @Description: 编辑资讯信息
	 * @param infos
	 * @return void
	 */
	public void  editInfos(Infos infos){
		Connection conn = BaseDao.getConnection();
		//资讯内容编码后保存
		infos.setInfo_content(Transcode.htmlEncode(infos.getInfo_content()));
		infosDao.updateInfos(infos,conn);
		
		BaseDao.closeDB(null, null, conn);
	}

	/**
	 * @Title: getInfos
	 * @Description: 资讯查询
	 * @param infos
	 * @return Infos
	 */
	public Infos  getInfos(Infos infos){
		Connection conn = BaseDao.getConnection();
		Infos _infos = infosDao.getInfos(infos, conn);
		BaseDao.closeDB(null, null, conn);
		return _infos;
	}
	 
	/**
	 * @Title: addInfos
	 * @Description: 添加资讯
	 * @param infos
	 * @return void
	 */
	public void  addInfos(Infos infos){
		Connection conn = BaseDao.getConnection();
		//资讯内容编码后保存
		infos.setInfo_content(Transcode.htmlEncode(infos.getInfo_content()));
		infosDao.addInfos(infos, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: updateInfos
	 * @Description: 更新资讯信息
	 * @param infos
	 * @return void
	 */
	public void  updateInfos(Infos infos){
		Connection conn = BaseDao.getConnection();
		//资讯内容编码后保存
		infos.setInfo_content(Transcode.htmlEncode(infos.getInfo_content()));
		infosDao.updateInfos(infos, conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: delInfoss
	 * @Description: 删除资讯信息
	 * @param infos
	 * @return void
	 */
	public void  delInfoss(Infos infos){
		Connection conn = BaseDao.getConnection();
		infosDao.delInfoss(infos.getIds().split(","), conn);
		BaseDao.closeDB(null, null, conn);
	}
	
	/**
	 * @Title: listComments
	 * @Description: 新闻评论查询
	 * @param comment
	 * @return List<Comment>
	 */
	public List<Comment>  listComments(Comment comment, int[] sum){
		Connection conn = BaseDao.getConnection();
		if (sum!=null) {
			sum[0] = commentDao.listCommentsCount(comment, conn);
		}
		List<Comment> comments = commentDao.listComments(comment,conn);
		
		BaseDao.closeDB(null, null, conn);
		return comments;
	}

	/**
	 * @Title: delComments
	 * @Description: 删除新闻评论信息
	 * @param comment
	 * @return void
	 */
	public void  delComments(Comment comment){
		Connection conn = BaseDao.getConnection();
		commentDao.delComments(comment.getIds().split(","), conn);
		BaseDao.closeDB(null, null, conn);
	}
}
